#include "menu_camera.h"
#include "menu_frame.h"
#include "language.h"
#include <stdio.h>
#include <string.h>

#ifdef _WIN32
#include <windows.h>
#else
#include <unistd.h>
#endif

const ST_MENU_IMAGE gstImageCamera = {"**********", "&"};

/* 摄像机菜单 */
ST_MENU_LIST gastCameraMenuTable[] = {
    MMI_MENU_ITEM_BIND("TEXT_PHOTO", NULL, NULL, NULL, MENU_OnCommonFunction, NULL),
    MMI_MENU_ITEM_BIND(TEXT_PHOTOGRAPHY, NULL, NULL, NULL, MENU_OnCommonFunction, NULL),
};

/* 摄像机菜单显示效果 */
static void MENU_ShowCameraMenu(ST_MENU_SHOW *ptShowInfo)
{
    uint8_t showNum = 3;
    uint8_t tmpselect;

    MMI_MenuLimitShowListNumber(ptShowInfo, &showNum);

    printf("\e[0;30;46m ------------- %s ------------- \e[0m\n", get_text(ptShowInfo->uMenuDesc.textId));

    for (int i = 0; i < showNum; i++)
    {
        tmpselect = i + ptShowInfo->showBaseItem;

        if (tmpselect == ptShowInfo->selectItem)
        {
            printf("\e[0;30;47m %d. %-34s\e[0m\n", tmpselect + 1, get_text(ptShowInfo->uItemsListDesc[tmpselect].textId));
        }
        else
        {
            printf("\e[7;30;47m %d. %-34s\e[0m\n", tmpselect + 1, get_text(ptShowInfo->uItemsListDesc[tmpselect].textId));
        }
    }
}

void MENU_CameraEnter(const ST_MENU_ITEM_INFO *pItemInfo)
{
    MMI_MenuBind(gastCameraMenuTable, MMI_GET_MENU_NUM(gastCameraMenuTable), MENU_ShowCameraMenu);
}

void MENU_CameraLoad(const ST_MENU_ITEM_INFO *pItemInfo)
{
    CLEAR();
    MOVETO(0, 0);
    printf("---%s-----\n", get_text(TEXT_LOADING));
}

void MENU_CameraExit(const ST_MENU_ITEM_INFO *pItemInfo)
{
    printf("--------------------------\n");
    printf("     %s%s...\n", get_text(TEXT_VIDEO), get_text(TEXT_STOPPING_PLAYBACK));
    printf("--------------------------\n");
#ifdef _WIN32
    Sleep(1000);
#else
    sleep(1);
#endif
}

void MENU_CameraTask(const ST_KEY_INFO *pKeyInfo, const ST_MENU_ITEM_INFO *pItemInfo)
{
#if 0
    int cmd;

    printf("%s(0-%s; 1-%s%s; 2-%s; 3-%s; 4-%s): ",
           get_text(TEXT_SELECT_OPTION), get_text(TEXT_RETURN), get_text(TEXT_RETURN), get_text(TEXT_MAIN_MENU),
           get_text(TEXT_ENTER), get_text(TEXT_NEXT), get_text(TEXT_PREVIOUS));
    scanf(" %d", &cmd); // 空格作用是忽略上次的回车

    switch (cmd)
    {
    case 0:
        MMI_MenuExit(true);
        break;
    case 1:
        MMI_MenuReset();
        break;
    case 2:
        MMI_MenuEnter();
        break;
    case 3:
        MMI_MenuSelectNext(true);
        break;
    case 4:
        MMI_MenuSelectPrev(true);
        break;

    default:
        break;
    }
#else
    if (!pKeyInfo)
        return;

    switch (pKeyInfo->code)
    {
    case EN_USER_KEY_SOFT4:
        MMI_MenuExit(false);
        break;
    case EN_USER_KEY_OK:
        MMI_MenuEnter();
        break;
    case EN_USER_KEY_RIGHT:
        MMI_MenuSelectNext(true);
        break;
    case EN_USER_KEY_LEFT:
        MMI_MenuSelectPrev(true);
        break;

    case EN_USER_KEY_8:
        MMI_MenuReset();
        break;
    default:
        break;
    }
    printf("%s(SOFT4-%s; 8-%s%s; OK-%s; RIGHT-%s; LEFT-%s):\n",
           get_text(TEXT_SELECT_OPTION), get_text(TEXT_RETURN), get_text(TEXT_RETURN), get_text(TEXT_MAIN_MENU),
           get_text(TEXT_ENTER), get_text(TEXT_NEXT), get_text(TEXT_PREVIOUS));
#endif
}